<?php

namespace plugin\admin\app\model;

use plugin\admin\app\model\Base;
use const support\banner_type_1;
use const support\banner_type_remarks;

/**
 * @property integer $id ID(主键)
 * @property string $banner_title 轮播标题
 * @property string $banner_icon 轮播图片
 * @property integer $sort 排序，排序越大越在前
 * @property integer $banner_type 轮播类型，0无，1商品详情，2分类
 * @property string $banner_value 场景值
 * @property integer $status 状态，1正常，2关闭
 * @property integer $create_time 创建时间
 * @property integer $update_time 更新时间
 */
class RlBanner extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'rl_banners';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    protected $appends=[
        'banner_type_text','banner_value_text','create_date'
    ];

    public function getBannerTypeTextAttribute()
    {
        return banner_type_remarks[$this->banner_type]??'未知';
    }

    public function getBannerValueTextAttribute()
    {
        if ($this->banner_type==banner_type_1){
            return RlGoods::where('id',$this->banner_value)->value('goods_title');
        }else{
            return RlGoodsCate::where('id',$this->banner_value)->value('cate_title');
        }
    }

    public function getCreateDateAttribute()
    {
        return $this->update_time?date('Y-m-d H:i:s',$this->update_time):'';
    }

}
